package com.mjh.zhujianju.controller.supervise;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.livew.framework.base.controller.RestBaseController;
import com.livew.framework.base.service.BaseService;
import com.livew.framework.exception.XTBusinessException;
import com.livew.framework.pojo.LoginUserInfo;
import com.livew.framework.utils.XTCurrentUser;
import com.mjh.zhujianju.model.supervise.SupervisionScheduleEO;
import com.mjh.zhujianju.service.supervise.SupervisionScheduleService;
import com.mjh.zhujianju.util.ApiConstant;
import com.mjh.zhujianju.util.JsonResult;
import com.mjh.zhujianju.vo.supervision.SupervisionScheduleVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @author: Alex
 * @version: V1.0
 * @project: zhujianju
 * @package: com.mjh.zhujianju.controller.supervise
 * @description: description
 * @date: 2018/9/5
 * @time: 上午8:46
 */
@RestController
@RequestMapping("/schedule")
@Api("2.督办->汇报")
public class SupervisionScheduleController extends RestBaseController<SupervisionScheduleEO> {

	@Autowired
	private SupervisionScheduleService supervisionScheduleService;

	@ApiOperation(value = "督办->新增汇报", notes = "对督办事项处理情况汇报")
	@RequestMapping(value = "/addSupervisionSchedule", method = RequestMethod.POST)
	@ApiImplicitParam(name = "督办处理程序类", value = "supervisionScheduleVO", required = true, dataType = "SupervisionScheduleVO")
	public ResponseEntity<JsonResult> addSupervisionSchedule(@RequestBody SupervisionScheduleVO supervisionScheduleVO) {
		JsonResult result = new JsonResult();
		try {
			SupervisionScheduleEO supervisionScheduleEO = new SupervisionScheduleEO();
			BeanUtils.copyProperties(supervisionScheduleVO, supervisionScheduleEO);
			LoginUserInfo info = XTCurrentUser.getCurrentUser();
			supervisionScheduleEO.setDeptId(info.getDeptId());
			supervisionScheduleEO.setUserId(info.getId());
			if (supervisionScheduleEO.getId() == null) {
				supervisionScheduleService.saveInfo(supervisionScheduleEO);
				result.setResult("新增汇报成功");
			} else {
				supervisionScheduleService.updateInfo(supervisionScheduleEO);
				result.setResult("修改汇报成功");
			}

			result.setStatus(ApiConstant.MSG_SUCCESS);
		} catch (XTBusinessException e) {
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			result.setStatus(ApiConstant.MSG_ERROR);
			e.printStackTrace();
		}
		return ResponseEntity.ok(result);
	}

	/**
	 * 详情
	 * 
	 * @param supervisionScheduleVO
	 * @return
	 */
	@RequestMapping(value = "/getSchedule/{id}", method = RequestMethod.GET)
	public ResponseEntity<JsonResult> getSchedule(@PathVariable("id") Long id) {
		JsonResult result = new JsonResult();
		try {
			SupervisionScheduleEO eo = supervisionScheduleService.getByPrimaryKey(id);
			result.setResult(eo);
			result.setStatus(ApiConstant.MSG_SUCCESS);
		} catch (XTBusinessException e) {
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			result.setStatus(ApiConstant.MSG_ERROR);
			e.printStackTrace();
		}
		return ResponseEntity.ok(result);
	}

	@Override
	protected BaseService<SupervisionScheduleEO> getService() {
		return supervisionScheduleService;
	}
}
